<template>
  <div>
    <common-header :headNav="headNav"></common-header>
    <div class="main">
      <div class="container">
        <div class="as_head"><span class="as_h_title">{{ examInfo.subjectName }}</span> <span
            class="as_h_br">{{ examInfo.typeName }}</span><span class="as_h_br"></span>
        </div>
        <div class="as_con">
          <img
              src="/static/img/exam/exam-result-header.png"
              alt="">
          <p class="as_head_title">{{ examInfo.paperName }}</p>
          <div class="as_c_time">本次用时{{getTime(examInfo.testTime)}}</div>
          <div class="as_c_i">
            <div class="as_c_box"><img
                    src=""
                    class="as_c_img">
              <div class="as_c_r"><p class="as_r_num">{{examInfo.userScore}}</p>
                <span class="as_r_font">得分</span></div>
            </div>

            <div class="as_c_box"><img
                src=""
                class="as_c_img">
              <div class="as_c_r">
                <p class="as_r_num" v-if="examInfo.qstCount > 0">{{Math.round(examInfo.correctNum/examInfo.qstCount*100)}}%</p>
                <p class="as_r_num" v-if="examInfo.qstCount == 0">0%</p>
                <span
                    class="as_r_font">正确率</span></div>
            </div>
            <div class="as_c_box"><img
                    src=""
                    class="as_c_img">
              <div class="as_c_r"><p class="as_r_num">{{ examInfo.doneCount }}</p>
                <span
                        class="as_r_font">做题量</span></div>
            </div>
<!--            <div class="as_c_box"><img
                src=""
                class="as_c_img">
              <div class="as_c_r"><p class="as_r_num">1</p>
                <span
                    class="as_r_font">排名</span></div>
            </div>-->
          </div>
<!--          <div class="as_c_rate">
            <div class="as_ra_box"><p class="as_ra_n"><span
                class="as_ra_new">50</span>%
            </p>
              <p class="as_ra_te">全站最高正确率</p></div>
            <div class="as_ra_box"><p class="as_ra_n"><span
                class="as_ra_new as_ra_new1">8.91</span>%
            </p>
              <p class="as_ra_te">全站平均正确率</p></div>
            <div class="as_ra_box"><p class="as_ra_n"><span
                class="as_ra_new as_ra_new2">100</span>%
            </p>
              <p class="as_ra_te">已击败考生</p></div>
          </div>-->
          <div class="as_c_btn">
            <router-link :to="{path:'/exam/examAnalysis',query:{id:this.examInfo.id} }" class="course-card">
              <div class="as_c_btn_comm">全部解析</div>
            </router-link>
            <div class="as_c_btn_comm" @click="toErrorList()">查看错题</div>
            <div class="as_c_btn_comm" @click="toAnswer()">再做一次</div>
            <div class="as_c_btn_comm" @click="toIndex()">返回首页</div>
          </div>
        </div>
        <div class="clear"></div>
      </div>
    </div>
    <common-footer></common-footer>
  </div>

</template>

<script>
import commonHeader from '@/views/common/header'
import commonFooter from '@/views/common/footer'
import {exampaperRecordById} from "@/api";
import {mapGetters} from "vuex";


export default {
  name: 'courseList',
  data() {
    return {
      headNav: "/exam/examIndex",
      exSuspendShow: true,
      examInfo:{
        paperName:' ',
        testTime:0,
        correctNum:0,
        qstCount:1
      }
    }
  }, components: {
    commonHeader, commonFooter
  },
  methods: {
    init(){
      //判断是否登录如果没有登录则去登录
      if(!this.isLogin){
        this.$router.push({ path: '/user/login' })
        return;
      }
      let id = this.$route.query.id;
      exampaperRecordById(id).then(res=>{
        this.examInfo = res.data.data
      })
    },
    getTime(s){
      //计算分钟
      //算法：将秒数除以60，然后下舍入，既得到分钟数
      var h;
      h  =   Math.floor(s/60);
      //计算秒
      //算法：取得秒%60的余数，既得到秒数
      s  =   s%60;
      //将变量转换为字符串
      h    +=    '';
      s    +=    '';
      //如果只有一位数，前面增加一个0
      h  =   (h.length==1)?'0'+h:h;
      s  =   (s.length==1)?'0'+s:s;
      return h+'分'+s+"秒";
    },
    toErrorList(){
        this.$router.push({ path: "/uc/examRecord", query:{active:2}});
    },
    toIndex(){
      this.$router.push({ path: "/exam/examIndex" });
    },
    toAnswer(){
      this.$router.push({ path: "/exam/examAnswer",query:{id:this.examInfo.epId} });
    }
  },
  mounted: function () {
    this.init()
  },
  computed: {
    ...mapGetters(["studentInfo","isLogin"]),
  },
}
</script>

<style scoped>

</style>
